[ 'method' => "GET", 'header' => "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) PHP-Reader\r\n" ] ]; $context = stream_context_create($options); $xml_content = @file_get_contents($rss_url, false, $context); if ($xml_content === false) { die("Не вдалося завантажити RSS."); } $rss = simplexml_load_string($xml_content); // Отримуємо назву каналу $channel_title = (string)$rss->channel->title; // Початок формування HTML $html_output = "\n\n\n"; $html_output .= "\n"; $html_output .= "\n"; $html_output .= "{$channel_title}\n"; $html_output .= "\n"; $html_output .= "\n\n
\n"; $html_output .= "

" . mb_strtoupper($channel_title) . "

\n\n"; // Реєстрація просторів імен для доступу до itunes:image $namespaces = $rss->getNamespaces(true); foreach ($rss->channel->item as $item) { $title = htmlspecialchars_decode((string)$item->title); $link = (string)$item->link; // Форматування дати $date = new DateTime($item->pubDate); $formattedDate = $date->format('d-m-Y H:i'); $description = (string)$item->description; // Отримання зображення з простору імен itunes $itunes = $item->children($namespaces['itunes']); $img_src = (string)$itunes->image->attributes()->href; // Якщо в itunes:image пусто, шукаємо в описі (про всяк випадок) if (!$img_src) { preg_match('/https?:\/\/[^"\'>]+\.(?:jpg|jpeg|png|gif|webp)/i', $description, $matches); $img_src = $matches[0] ?? ''; } // 1. ВИЛУЧЕННЯ тегів

разом із вмістом $description_filtered = preg_replace('/]*>.*?<\/p>/is', '', $description); // 2. Вилучення порожніх пар тегів

$description_filtered = preg_replace('/]*>\s*( )*\s*<\/p>/i', '', $description_filtered); // 3. Очищення від решти HTML-тегів $clean_description = strip_tags($description_filtered); // 4. Очищення від зайвих пробілів $clean_description = trim($clean_description); // Формування блоку новини $html_output .= "

\n"; $html_output .= "
\n"; $html_output .= " {$title}\n"; $html_output .= " {$formattedDate}\n"; $html_output .= "
\n"; $html_output .= "
\n"; if ($img_src) { $html_output .= "
\n"; $html_output .= " " . htmlspecialchars($title) . "\n"; $html_output .= "
\n"; } $html_output .= "
{$clean_description}
\n"; $html_output .= "
\n"; $html_output .= "
\n"; } $html_output .= "
\n\n"; // Робота з директорією $dir = __DIR__ . '/Архів Медіа'; if (!is_dir($dir)) { mkdir($dir, 0777, true); } // Збереження результату $filename = $dir . '/Українське радіо та подкасти.html'; file_put_contents($filename, $html_output); ?>